package org.jason.interaction.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jason.interaction.mq.producer.CommentProducer;
import org.jason.interaction.service.ICommentService;
import org.jason.model.common.dtos.ResponseResult;
import org.jason.model.interaction.dtos.DeleteCommentDto;
import org.jason.model.interaction.dtos.LoadCommentsDto;
import org.jason.model.interaction.dtos.SendCommentDto;
import org.jason.model.interaction.es.ArticleComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "评论模块", value = "CommentController")
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private ICommentService commentService;

    @Autowired
    private CommentProducer commentProducer;

    //发送评论
    @ApiOperation("发送评论")
    @PostMapping("/send_comment")
    @SaCheckLogin
    public ResponseResult sendComment(@RequestBody @Validated SendCommentDto dto) {
        return commentProducer.createComment(dto);
    }

    //加载文章评论
    @ApiOperation("加载文章评论")
    @SaIgnore
    @PostMapping("/load_comments")
    public ResponseResult<List<ArticleComment>> loadComments(@RequestBody @Validated LoadCommentsDto dto) {
        return commentService.loadComments(dto);
    }

    //删除评论
    @ApiOperation("删除评论")
    @SaCheckLogin
    @DeleteMapping
    public ResponseResult delComment(@RequestBody @Validated DeleteCommentDto dto) {
        return commentService.delComment(dto);
    }
}
